package com.algorithm;

/**
 * @author: sun.hongliang
 * @create: 2019/07/13 14:27
 */
public class PalindromeTest {
    public static void main(String[] args) {
        boolean palindrome = isPalindrome(121);
        System.out.println(palindrome);
    }

    public static boolean isPalindrome(int x) {
        if (x < 0 || (x % 10 == 0 && x != 0)) {
            return false;
        }
        int rev = 0;
        while (rev < x) {
            rev = x % 10 + rev * 10;
            x = x / 10;
        }
        return x == rev || rev / 10 == x;
    }
}
